package com.dlwx.firefighting.activity;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.PixelFormat;
import android.os.Bundle;

import android.widget.ImageView;

import com.tencent.smtt.sdk.WebChromeClient;
import com.tencent.smtt.sdk.WebView;
import com.tencent.smtt.sdk.WebViewClient;
import com.dlwx.firefighting.R;
import com.dlwx.firefighting.utils.DialogUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class WebActivity extends Activity {

//    @BindView(R.id.webView)
//    WebView webView;
    @BindView(R.id.close_img)
    ImageView closeImg;
    String url;
    @BindView(R.id.web)
    com.tencent.smtt.sdk.WebView web;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFormat(PixelFormat.TRANSLUCENT);
        setContentView(R.layout.activity_web);
//        url = "https://v.qq.com/iframe/player.html?vid=t0530uuyeu6&tiny=0&auto=0";
        url=getIntent().getStringExtra("url");
        ButterKnife.bind(this);
//        initWeb();
        initWeb1();
    }

    private void initWeb1() {


        Bundle data = new Bundle();

        data.putBoolean("standardFullScreen", false);
//true表示标准全屏，false表示X5全屏；不设置默认false，

        data.putBoolean("supportLiteWnd", false);
//false：关闭小窗；true：开启小窗；不设置默认true，

        data.putInt("DefaultVideoScreen", 2);
//1：以页面内开始播放，2：以全屏开始播放；不设置默认：1

//        web.getX5WebViewExtension().invokeMiscMethod("setVideoParams", data);

        web.getSettings().setJavaScriptEnabled(true);// 支持js
        web.getSettings().setUseWideViewPort(true); //自适应屏幕
        web.setWebChromeClient(new WebChromeClient());

        web.setWebViewClient(new WebViewClient(){
            @Override
            public void onPageStarted(WebView webView, String s, Bitmap bitmap) {
                super.onPageStarted(webView, s, bitmap);
                DialogUtils.showProgressDlg(WebActivity.this,"");
            }

            @Override
            public void onPageFinished(WebView webView, String s) {
                super.onPageFinished(webView, s);
                DialogUtils.stopProgressDlg();
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView webView, String s) {
                return false;
            }
        });
        web.loadUrl(url);
    }


    private void initWeb() {

//        WebSettings setting = webView.getSettings();
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//            setting.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
//        }
//        setting.setJavaScriptEnabled(true);
//        setting.setPluginState(WebSettings.PluginState.ON);
//        setting.setJavaScriptCanOpenWindowsAutomatically(true);
//        setting.setAllowFileAccess(true);
//        setting.setDefaultTextEncodingName("UTF-8");
//        setting.setLoadWithOverviewMode(true);
//        setting.setUseWideViewPort(true);
//        setting.setSupportMultipleWindows(true);
//        webView.setWebChromeClient(new WebChromeClient());
     /*   webView.setWebViewClient(new WebViewClient(){
            @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                view.loadUrl(request.getUrl().toString());
                return false;
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return false;
            }
        });*/
//        webView.loadUrl(url);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        web.destroy();
//        webView.destroy();
    }

    @OnClick(R.id.close_img)
    public void onViewClicked() {
//        webView.destroy();
        this.finish();
    }
}
